package uvv001;
import robocode.*;

public class EnemyBot {
	private double bearing, distance, energy, heading, velocity, x, y;
	private String name;

	public EnemyBot() {
		reset();
	}
	
	public double getBearing() {
		return bearing;
	}
	
	public double getDistance() {
		return distance;
	}
	
	public double getEnergy() {
		return energy;
	}

	public double getHeading() {
		return heading;
	}
	
	public double getVelocity() {
		return velocity;
	}
	
	public String getName() {
		return name;
	}
	
	public double getNextX(double time) {
		return x + Math.sin(Math.toRadians(getHeading())) * getVelocity() * time;
	}
	
	public double getNextY(double time) {
		return y + Math.cos(Math.toRadians(getHeading())) * getVelocity() * time;
	}

	public double getX() {
		return x;
	}
	
	public double getY() {
		return y;
	}

	public void update(ScannedRobotEvent e, Robot robot) {
		bearing = e.getBearing();
		distance = e.getDistance();
		energy = e.getEnergy();
		heading = e.getHeading();
		velocity = e.getVelocity();
		name = e.getName();
		
		double absBearingDeg = (robot.getHeading() + e.getBearing());
		
		if (absBearingDeg < 0) {
			absBearingDeg += 360;
		}
		
		x = robot.getX() + Math.sin(Math.toRadians(absBearingDeg)) * e.getDistance();
		y = robot.getY() + Math.cos(Math.toRadians(absBearingDeg)) * e.getDistance();
	}
	
	public void reset() {
		bearing = 0;
		distance = 0;
		energy = 0;
		heading = 0;
		velocity = 0;
		name = "";
		x = 0;
		y = 0;
	}
	
	public boolean none() {
		return name.length() == 0;
	}
}

